home *** CD-ROM | disk | FTP | other *** search
/ Info-Mac 4 / Info_Mac IV CD-ROM (Pacific HiTech Inc.)(August 1994).iso / Applications / Tax ƒ / Tax.p < prev   
Text File  |  1994-05-07  |  3KB  |  95 lines

  1.  
  2. {                                    Tax.p                                            }
  3.  
  4. {                        Source file for Tax FKEY                            }
  5.  
  6. {            Since this was written in THINK Pascal, some portions might be            }
  7.  
  8. {            copyrighted to Symantec Corporation.            }
  9.  
  10.  
  11. {        Copyright © 1993, 1994 by David Alten. All rights reserved.        }
  12.  
  13. {    version 1.0.1    }
  14.  
  15.  
  16. unit myFKEY;
  17. interface
  18.  
  19.     procedure main;        {    all code resources must have a MAIN procedure        }
  20.  
  21. implementation
  22.  
  23.     procedure main;
  24.         const
  25.             tax = 1.0825;        {    the tax rate in TX is 8.25%        }
  26.         label
  27.             0;
  28.         type
  29.             IndexType = 1..12;        {    If you make more than this many digits, you can probably hire        }
  30.                                         {    an accountant to do the work for you!!!        }
  31.  
  32. { PACs are better than STRINGS, especially if they are 4 bytes long }
  33.  
  34.             PACType = packed array[indextype] of char;
  35.             PACPtrType = ^PACType;
  36.  
  37.         var
  38.             aHandle: handle;                    { Handle to Text from Scrap }
  39.             thePACPtr: PACPtrType;            { Same as PACPtr in argument, }
  40.                                             { use PACPtr to avoid static link }
  41.                                             { overhead }
  42.             Offset, theScrapLength, num: longint;
  43.             thenum: str255;
  44.  
  45. {    convert a character digit to a number        }
  46.         function number (ch: char): integer;
  47.         begin
  48.             number := -1;
  49.             if (ch >= '0') and (ch <= '9') then
  50.                 number := ord(ch) - 48;
  51.         end;
  52.  
  53.     begin
  54.         aHandle := NewHandle(0);
  55.         theScrapLength := GetScrap(aHandle, 'TEXT', Offset);
  56.         if (theScrapLength <= 0) or (aHandle = nil) or (theScrapLength > 10) then
  57.             goto 0;        {    quit        }
  58.         HLock(aHandle);
  59.         thePACPtr := PACPtrType(aHandle^);
  60.         num := 0;
  61.         for Offset := 1 to theScrapLength do
  62.             if number(thePACPtr^[Offset]) >= 0 then        {    ignore characters in between        }
  63.                 num := num * 10 + number(thePACPtr^[Offset]);
  64.  
  65. {    check to see if you only one digit after the decimal point; adjust if you do        }
  66.         if (thePACPtr^[theScrapLength - 1] = '.') then
  67.             num := num * 10;
  68.  
  69. {    compute the new number and convert it to a string        }
  70.         numtostring(round(num * tax), thenum);
  71.  
  72. {    you will get two decimal places        }
  73.         insert('.', thenum, length(thenum) - 1);
  74.  
  75. {    if your result is less than 10 cents, you get something like ".4" instead of ".04"        }
  76.         if length(thenum) = 2 then
  77.             insert('0', thenum, length(thenum));
  78.  
  79.         offset := ZeroScrap;        {    clear the clipboard        }
  80.  
  81. {    copy the stuff back in the clipboard        }
  82.         if Offset = noerr then
  83.             Offset := PutScrap(length(thenum), 'TEXT', @thenum[1]);    {    thenum[0] contains the length        }
  84.  
  85. 0:
  86.         HUnlock(aHandle);
  87.         if aHandle <> nil then        {    ALWAYS check to see if a Handle        }
  88.                                             {    is NIL before disposing it        }
  89.             DisposHandle(aHandle);
  90.  
  91.     end;
  92. end.        {    THE END!!        }
  93.  
  94. { HE KUER!! }
  95.